package string.compare;

/**
 * @Classname : ValidAnagram
 * @Description : 242. 有效的字母异位词
 * https://leetcode.cn/problems/valid-anagram/
 * @Author : chentianyu
 * @Date 2022/12/7 22:31
 */


public class ValidAnagram {
    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) return false;

        int[] table = new int[26];
        for (char c : s.toCharArray()) {
            table[c - 'a']++;
        }
        for (char c : t.toCharArray()) {
            if (--table[c - 'a'] < 0) return false;
        }
        return true;
    }
}
